import re
import time
import requests
from django.template.defaultfilters import title

from util.logger import get_looger
import shutil
import os

logger = get_looger("豆瓣250.log",__file__)
logger.info("启动")



url = "https://movie.douban.com/top250?start=0&filter="

headers = {
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
}

root = "static/豆瓣250/"
if os.path.exists(root):
    shutil.rmtree(root)
os.makedirs(root)



res = requests.get(url,headers=headers)
# print(res.status_code)
content = res.text
items = re.findall(r'<div class="pic">.*?href="(.*?)">.*?alt="(.*?)" src="(.*?)">.*?</div>',content,re.S)
# print(items)
for item in items:
    time.sleep(1)
    link = item[0]
    title = item[1]
    img_url = item[2]
    print(item)

